package com.chengjue.service.impl;

import com.chengjue.common.ServerResponse;
import com.chengjue.mapper.TbItemMapper;
import com.chengjue.pojo.TbItem;
import com.chengjue.pojo.TbItemExample;
import com.chengjue.service.ItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品管理 Service
 */

@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    TbItemMapper tbItemMapper;

    /**
     * 根据主键查询
     * @param id  商品id
     * @return
     */
    @Override
    public TbItem getItmById(Long id) {
        return tbItemMapper.selectByPrimaryKey(id);
    }


    @Override
    public ServerResponse getItemList(Integer pageNo, Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<TbItem> list = tbItemMapper.selectByExample(new TbItemExample());
        if(null != list && list.size()>0){
            PageInfo pageInfo = new PageInfo(list);
            return ServerResponse.createBySuccess(pageInfo);
        }
        return ServerResponse.createBySuccessMessage("数据异常");
    }
}
